//#include "app_state.h"
//#include "user_app_sub.h"


////void MotorStop(void)
////{
////    PWMIO_InitState();
////    gS_Motor.eFSM = E_FSM_SYS_INIT;
////}


//void MotorPreCharge(void)
//{
//    REG_UpperbridgeIOmode();
//    SET_CCR1_VAL(gS_Motor.mS_Para.unPreChargeDuty);
//    SET_CCR2_VAL(gS_Motor.mS_Para.unPreChargeDuty);
//    SET_CCR3_VAL(gS_Motor.mS_Para.unPreChargeDuty);
//    REG_PWM_Out_Enable();

//    if (--gS_Motor.mS_Para.unPreChargeTime == 0)
//    {
//        REG_PWM_Out_Disable();
//        REG_UpperbridgePWMmode();
//        gS_Motor.eFSM = E_FSM_SYS_ALIGN;
//    }
//}


//void MotorAlign(STR_Motor_Def *tS_M)
//{
//    static u16 s_unCnt = 0;

//#if(RAMP_MODE == ADAPTIVE_RAMP)
//    tS_M->mS_Para.unAlign1stTime = 0;
//    tS_M->mS_Para.unAlign2ndTime = 0;
//#endif

//    if (++s_unCnt >= tS_M->mS_Para.unPWMIRQ1kHzCntTarget) //1khz loop
//    {
//        s_unCnt = 0;

//        if (tS_M->mS_Para.unAlign1stCurrIncrTime > 0)
//        {
//            tS_M->mS_Ctr.unThetaCmd = 0;
//            tS_M->mS_Para.unAlign1stCurrIncrTime--;
//            tS_M->mS_Ctr.nIqCmdReq = tS_M->mS_Para.nAlign1stCurr;
//            tS_M->mS_Ctr.nDeltaIqFactor = tS_M->mS_Para.nAlign1stAccCurr;
//        }
//        else if (tS_M->mS_Para.unAlign1stTime > 0)
//        {
//            tS_M->mS_Para.unAlign1stTime--;
//        }
//        else if (tS_M->mS_Para.unAlign2ndCurrIncrTime > 0)
//        {
//            tS_M->mS_Ctr.unThetaCmd = 16384;
//            tS_M->mS_Para.unAlign2ndCurrIncrTime--;
//            tS_M->mS_Ctr.nIqCmdReq = tS_M->mS_Para.nAlign2ndCurr;
//            tS_M->mS_Ctr.nDeltaIqFactor = tS_M->mS_Para.nAlign2ndAccCurr;
//        }
//        else if (tS_M->mS_Para.unAlign2ndTime > 0)
//        {
//            tS_M->mS_Para.unAlign2ndTime--;
//        }

//        Iq_ACC(tS_M);
//    }

//    if (tS_M->mS_Para.unAlign1stTime == 0 && tS_M->mS_Para.unAlign2ndTime == 0)
//    {
//        tS_M->mS_Ctr.uwThetaCmdBuf  = tS_M->mS_Ctr.unThetaCmd << 16;

//#if(RAMP_MODE == SYNC_RAMP)
//        tS_M->eFSM = E_FSM_SYS_RAMP;
//        tS_M->mS_Ctr.nDeltaWrFactor = tS_M->mS_Para.nRampDeltaWrFactor;

//        if (tS_M->eDIR_CMD == E_CW)
//            tS_M->mS_Ctr.vnSpdCmdReq    = tS_M->mS_Para.nRampSpdCmdReq;
//        else
//            tS_M->mS_Ctr.vnSpdCmdReq    = -tS_M->mS_Para.nRampSpdCmdReq;

//        tS_M->mS_Ctr.vnSpdCmd       = 0;
//        tS_M->mS_Ctr.nDeltaIdFactor = tS_M->mS_Para.nRampAccCurr;
//        tS_M->mS_Ctr.nIqCmdReq      = tS_M->mS_Para.nRampCurrCmdReq;
//        tS_M->mS_Ctr.nDeltaIqFactor = tS_M->mS_Para.nRampAccCurr;
//#endif

//#if(RAMP_MODE == ADAPTIVE_RAMP)
//        tS_M->mS_Ctr.nDeltaIqFactor = tS_M->mS_Para.nAdaptiveRampAccCurr;
//        tS_M->mS_Ctr.nIqCmdReq      = tS_M->mS_Para.nAdaptiveRampCurrCmdReq;
//        tS_M->eFSM = E_FSM_SYS_ADAPTIVERAMP;

//        /*LIB_ADAPTIVERAMP_INIT();*/
//#endif
//    }

//    FOC_CurrLoop_Output(tS_M);
//    SVPWM_2R(tS_M, &gS_SVM);
//    REG_PWM_Duty_Ctr(&gS_SVM);
//}


//void MotorAdaptiveRamp(STR_Motor_Def *tS_M)
//{
//    static u16 s_unCnt = 0;
//    s16 t_nSpd = 0;

//    t_nSpd = LIB_OB_MOTOR_SPD;
//    tS_M->mS_Ctr.unThetaCmd = LIB_OB_MOTOR_THETA;

//    if (++s_unCnt >= tS_M->mS_Para.unPWMIRQ1kHzCntTarget) //1khz loop
//    {
//        s_unCnt = 0;
//        Iq_ACC(tS_M);

//        if (ABS(t_nSpd) >= tS_M->mS_Para.nAdaptiveRampSpdTarget)
//        {
//            if (tS_M->mS_Para.unAdaptiveRampStableTime > 0) tS_M->mS_Para.unAdaptiveRampStableTime--;

//            if (tS_M->mS_Para.unAdaptiveRampStableTime == 0)
//            {
//                tS_M->eFSM = E_FSM_SYS_RUN;
//                tS_M->mS_Ctr.nDeltaWrFactor = tS_M->mS_Para.nRunDeltaWrFactor;
//                gS_SPD_PI.wUi_15 = tS_M->mS_Ctr.nIqCmd << 15;
//                tS_M->mS_Ctr.vnSpdCmdReq = t_nSpd;
//                tS_M->mS_Ctr.nCmdReq     = t_nSpd;
//                tS_M->mS_Ctr.vnSpdCmd    = t_nSpd;
//#if(P_LOOP_MODE == P_LOOP_POWER)
//                gS_Power_PI.wUi_15 = t_nSpd << 15;
//                if (tS_M->eDIR_CMD == E_CCW) gS_Power_PI.wUi_15 = -gS_Power_PI.wUi_15;
//                tS_M->mS_Ctr.nCmdReq = P_POWER_CMD_MIN_VALUE;
//#endif
//            }
//        }
//        else tS_M->mS_Para.unAdaptiveRampStableTime = ADAPTIVERAMP_STABLE_TIME_PARA;
//    }

//    FOC_CurrLoop_Output(tS_M);
//    SVPWM_2R(tS_M, &gS_SVM);
//    REG_PWM_Duty_Ctr(&gS_SVM);
//}


//void MotorRamp(STR_Motor_Def *tS_M)
//{
////#if(RAMP_MODE == SYNC_RAMP)

//    static u16 s_unCnt = 0;
//    static u8 s_ub10kHzCnt = 0;

//    if (++s_unCnt >= tS_M->mS_Para.unPWMIRQ1kHzCntTarget) //1khz loop
//    {
//        s_unCnt = 0;
//        Iq_ACC(tS_M);

//        if (tS_M->mS_Para.unRampStableTime > 0 && tS_M->mS_Ctr.vnSpdCmdReq == tS_M->mS_Ctr.vnSpdCmd)
//        {
//            tS_M->mS_Para.unRampStableTime--;
//        }

//        if (++s_ub10kHzCnt >= 10) //10khz loop
//        {
//            s_ub10kHzCnt = 0;
//            Spd_ACC(&gS_Motor);
//        }
//    }

//    tS_M->mS_Ctr.uwThetaCmdBuf += tS_M->mS_Ctr.vnSpdCmd * tS_M->mS_Para.nSpdToThetaGain;


//    tS_M->mS_Ctr.unThetaCmd = tS_M->mS_Ctr.uwThetaCmdBuf >> 16;

//    if (tS_M->mS_Ctr.vnSpdCmdReq == tS_M->mS_Ctr.vnSpdCmd)
//    {
//        if (tS_M->mS_Para.unRampStableTime == 0)
//        {
//#ifndef VF_OPENLOOP_MODE
//            if (tS_M->mS_Ctr.unThetaCmd > 16384 && tS_M->mS_Ctr.unThetaCmd < 21845)
//            {
//                tS_M->eFSM = E_FSM_SYS_RUN;
//                gS_SPD_PI.wUi_15 = tS_M->mS_Ctr.nIqCmd << 15;
//                tS_M->mS_Ctr.nDeltaWrFactor = tS_M->mS_Para.nRunDeltaWrFactor;
//                LIB_RAMP_STABLE();
//            }
//#endif
//        }
//    }

//    FOC_CurrLoop_Output(tS_M);
//    SVPWM_2R(tS_M, &gS_SVM);
//    REG_PWM_Duty_Ctr(&gS_SVM);

////#endif
//}

//void MotorReverseRamp(STR_Motor_Def *tS_M)
//{
//    static u16 s_unCnt = 0;
//    static u8 s_ub10kHzCnt = 0;

//    if (++s_unCnt >= tS_M->mS_Para.unPWMIRQ1kHzCntTarget) //1khz loop
//    {
//        s_unCnt = 0;
//        Iq_ACC(tS_M);
//        Id_ACC(tS_M);

//        if (++s_ub10kHzCnt >= 10) //10khz loop
//        {
//            s_ub10kHzCnt = 0;
//            Spd_ACC(&gS_Motor);
//        }
//    }


//    tS_M->mS_Ctr.uwThetaCmdBuf -= tS_M->mS_Ctr.vnSpdCmd * tS_M->mS_Para.nSpdToThetaGain;

//    tS_M->mS_Ctr.unThetaCmd = tS_M->mS_Ctr.uwThetaCmdBuf >> 16;

//    if (tS_M->mS_Ctr.vnSpdCmdReq == tS_M->mS_Ctr.vnSpdCmd)
//    {
//        REG_UpperbridgePWMmode();
//        REG_PWM_Out_Enable();
//        ReverseRampParaInit();
//    }

//    FOC_CurrLoop_Output(tS_M);
//    SVPWM_2R(tS_M, &gS_SVM);
//    REG_PWM_Duty_Ctr(&gS_SVM);

//}



//void MotorRun(STR_Motor_Def *tS_M)
//{
//    tS_M->mS_Ctr.unThetaCmd = LIB_OB_MOTOR_THETA;
//    FOC_CurrLoop_Output(tS_M);
//    SVPWM_2R(tS_M, &gS_SVM);
//    REG_PWM_Duty_Ctr(&gS_SVM);
//}

//void MotorRunTrans(STR_Motor_Def *tS_M)
//{
//    static u16 s_unCnt = 0;

//    if (++s_unCnt >= tS_M->mS_Para.unPWMIRQ1kHzCntTarget) //1khz loop
//    {
//        s_unCnt = 0;
//        if (tS_M->mS_Para.unTransRunTime-- == 0)
//        {
//            gS_Motor.eFSM = E_FSM_SYS_RUN;
//            tS_M->mS_Ctr.nIqCmd = tS_M->mS_Ctr.nIqCmdReq;
//#if(P_LOOP_MODE == P_LOOP_POWER)
//            gS_Power_PI.wUi_15 = tS_M->mS_Ctr.vnSpdCmd << 15;
//            if (tS_M->eDIR_CMD == E_CCW) gS_Power_PI.wUi_15 = -gS_Power_PI.wUi_15;
//            tS_M->mS_Ctr.nCmdReq = P_POWER_CMD_MIN_VALUE;
//#endif
//        }
//    }

//    tS_M->mS_Ctr.nIdCmd = 0;
//    tS_M->mS_Ctr.nIqCmd = 0;

//    tS_M->mS_Ctr.unThetaCmd = LIB_OB_MOTOR_THETA;
//    FOC_CurrLoop_Output(tS_M);
//    SVPWM_2R(tS_M, &gS_SVM);
//    REG_PWM_Duty_Ctr(&gS_SVM);
//}

//void MotorSoftstop(STR_Motor_Def *tS_M)
//{
//    static u16 s_unCnt = 0;
//    s16 t_nSpd = 0;

//    if (++s_unCnt >= tS_M->mS_Para.unPWMIRQ1kHzCntTarget) //1khz loop
//    {
//        s_unCnt = 0;

//        if (tS_M->mS_Para.unSoftstopTimeTH > 0)
//        {
//            tS_M->mS_Para.unSoftstopTimeTH--;

//            if (tS_M->eDIR_CMD == E_CW)
//            {
//                tS_M->mS_Ctr.nIdCmd =  tS_M->mS_Para.nSoftstopIdCmd;
//                tS_M->mS_Ctr.nIqCmd = -tS_M->mS_Para.nSoftstopIqCmd;
//            }
//            else
//            {
//                tS_M->mS_Ctr.nIdCmd = -tS_M->mS_Para.nSoftstopIdCmd;
//                tS_M->mS_Ctr.nIqCmd = -tS_M->mS_Para.nSoftstopIqCmd;
//            }
//        }
//        else
//        {
//            tS_M->eFSM = E_FSM_SYS_STOP;
//        }
//    }

//    t_nSpd = LIB_OB_MOTOR_SPD;

//    //CW
//    if (ABS(t_nSpd) < tS_M->mS_Para.nSoftstopSpdTH)
//    {
//        tS_M->eFSM = E_FSM_SYS_STOP;
//    }

//    tS_M->mS_Ctr.unThetaCmd = LIB_OB_MOTOR_THETA;
//    FOC_CurrLoop_Output(tS_M);
//    SVPWM_2R(tS_M, &gS_SVM);
//    REG_PWM_Duty_Ctr(&gS_SVM);

//}

////#define DET_STATE_REVERSE_LOWSPD    (6)
////#define DET_STATE_REVERSE_HIGHSPD   (7)

//#define BRAKE_SYNC_RAMP             (1)
//#define BRAKE_ACTIVE_RAMP           (2)
//#define BRAKE_SYNC_REVERSERAMP      (3)
//#define BRAKE_TO_RAMP_MODE          BRAKE_SYNC_REVERSERAMP

//void MotorBrake(STR_Motor_Def *tS_M)
//{
//    static u16 s_unCnt = 0;
//    static u16 s_nDelayCnt = 0;

//    //Non Reverse mode --> Quit Brake Mode
//    if (gS_DetBEMF.ubDetState != 7 && gS_DetBEMF.ubDetState != 6) tS_M->mS_Para.unBrakeTime = 0;

//    if (ubSpd_Det(tS_M) == 1 && tS_M->mS_Para.unBrakeTime != 0)
//    {
//        if (gS_DetBEMF.ubDetState == 7 || gS_DetBEMF.ubDetState == 6)//reverse startup
//        {

////foward ramp
//#if(BRAKE_TO_RAMP_MODE == BRAKE_SYNC_RAMP)
//            //sync ramp
//            ParameterInit();
//            tS_M->mS_Ctr.nDeltaWrFactor = tS_M->mS_Para.nRampDeltaWrFactor;

//            if (tS_M->eDIR_CMD == E_CW)
//                tS_M->mS_Ctr.vnSpdCmdReq    = tS_M->mS_Para.nRampSpdCmdReq;
//            else
//                tS_M->mS_Ctr.vnSpdCmdReq    = -tS_M->mS_Para.nRampSpdCmdReq;

//            tS_M->mS_Ctr.vnSpdCmd       = 0;
//            tS_M->mS_Ctr.nDeltaIdFactor = tS_M->mS_Para.nRampAccCurr;
//            tS_M->mS_Ctr.nIqCmdReq      = tS_M->mS_Para.nRampCurrCmdReq;
//            tS_M->mS_Ctr.nDeltaIqFactor = tS_M->mS_Para.nRampAccCurr;
//            tS_M->mS_Ctr.nIqCmd         = tS_M->mS_Ctr.nIqCmdReq;
//            REG_UpperbridgePWMmode();
//            REG_PWM_Out_Enable();
//            tS_M->eFSM = E_FSM_SYS_RAMP;

//#elif(BRAKE_TO_RAMP_MODE == BRAKE_ACTIVE_RAMP)
//            //adaptive ramp
//            ParameterInit();
//            tS_M->mS_Ctr.nDeltaIqFactor = tS_M->mS_Para.nAdaptiveRampAccCurr;
//            tS_M->mS_Ctr.nIqCmdReq      = tS_M->mS_Para.nAdaptiveRampCurrCmdReq;
//            LIB_ADAPTIVERAMP_INIT();
//            REG_UpperbridgePWMmode();
//            REG_PWM_Out_Enable();
//            tS_M->eFSM = E_FSM_SYS_ADAPTIVERAMP;

//#elif(BRAKE_TO_RAMP_MODE == BRAKE_SYNC_REVERSERAMP)     //sync reverse ramp
//            tS_M->mS_Ctr.uwThetaCmdBuf  = (tS_M->mS_Ctr.unBrakeThetaOut + (0)) << 16;
//            tS_M->mS_Ctr.nDeltaWrFactor = tS_M->mS_Para.nReverseRampDeltaWrFactor;
//            tS_M->mS_Ctr.vnSpdCmdReq    = 0;

//            if (tS_M->eDIR_CMD == E_CW)
//                tS_M->mS_Ctr.vnSpdCmd       = tS_M->mS_Ctr.nBrakeSpdOut;//tS_M->mS_Para.unBrakeQuitSpdPU;
//            else
//                tS_M->mS_Ctr.vnSpdCmd       = -tS_M->mS_Ctr.nBrakeSpdOut;//-tS_M->mS_Para.unBrakeQuitSpdPU;


//            tS_M->mS_Ctr.nIdCmd = 0;
//            tS_M->mS_Ctr.nIqCmd = tS_M->mS_Para.nReverseRampCurrCmdReq;

//            tS_M->mS_Ctr.nDeltaIdFactor = tS_M->mS_Para.nRampAccCurr;
//            tS_M->mS_Ctr.nIqCmdReq      = tS_M->mS_Para.nReverseRampCurrCmdReq;
//            tS_M->mS_Ctr.nDeltaIqFactor = tS_M->mS_Para.nRampAccCurr;
//            tS_M->eFSM = E_FSM_SYS_REVERSERAMP;

//            tS_M->mS_Ctr.nIdCmdReq      = 0;
//            tS_M->mS_Ctr.nDeltaIdFactor = tS_M->mS_Para.nRampAccCurr;

//            REG_UpperbridgePWMmode();
//            REG_PWM_Out_Enable();

//#endif

//        }
//        else
//            tS_M->eFSM = E_FSM_SYS_STOP;
//    }

//    if (++s_unCnt >= tS_M->mS_Para.unPWMIRQ1kHzCntTarget) //1khz loop
//    {
//        s_unCnt = 0;
//        if (tS_M->mS_Para.unBrakeTime > 0) tS_M->mS_Para.unBrakeTime--;

//        if (tS_M->mS_Para.unBrakeTime == 0)// brake time is zero
//        {
//            if (gS_DetBEMF.ubDetState == 7 || gS_DetBEMF.ubDetState == 6)//wind is too strong -> retry
//            {
//                REG_PWM_Out_Disable();

//                if (s_nDelayCnt++ >= 2000)//2sec
//                    tS_M->eFSM = E_FSM_SYS_STOP;
//            }
//            else
//                tS_M->eFSM = E_FSM_SYS_STOP;
//        }
//        else if (tS_M->eFSM == E_FSM_SYS_BRAKE)
//        {
//            //three phase short brake
//            s_nDelayCnt = 0;
//            REG_UpperbridgeIOmode();
//            SET_CCR1_VAL(tS_M->mS_Para.unREGPWMPeriod);//real duty = 1-val
//            SET_CCR2_VAL(tS_M->mS_Para.unREGPWMPeriod);
//            SET_CCR3_VAL(tS_M->mS_Para.unREGPWMPeriod);
//            REG_PWM_Out_Enable();
//        }
//    }

//}

//void MotorIPD(STR_Motor_Def *tS_M)
//{
//    /*IPD(&gS_IPD, tS_M);*/


//    tS_M->mS_Ctr.nVqComp = tS_M->mS_Ctr.nVq;
//    tS_M->mS_Ctr.nVdComp = tS_M->mS_Ctr.nVd;
//    tS_M->mS_Ctr.mS_TrigSinCos = gS_TrigFunctions(tS_M->mS_Ctr.unThetaCmd);
//    //inverse park

//    tS_M->mS_Ctr.nValpha = (tS_M->mS_Ctr.nVdComp * tS_M->mS_Ctr.mS_TrigSinCos.hCos - tS_M->mS_Ctr.nVqComp * tS_M->mS_Ctr.mS_TrigSinCos.hSin) >> 15;
//    tS_M->mS_Ctr.nVbeta  = (tS_M->mS_Ctr.nVdComp * tS_M->mS_Ctr.mS_TrigSinCos.hSin + tS_M->mS_Ctr.nVqComp * tS_M->mS_Ctr.mS_TrigSinCos.hCos) >> 15;

//    SVPWM_2R(tS_M, &gS_SVM);
//    REG_PWM_Duty_Ctr(&gS_SVM);

//}

//void MotorReverse(STR_Motor_Def *tS_M)
//{
//    static u16 s_unCnt = 0;


//    ReverseLIB(tS_M);

//    if (++s_unCnt >= tS_M->mS_Para.unPWMIRQ1kHzCntTarget) //1khz loop
//    {
//        s_unCnt = 0;

//#if 1
//        //Brake mode
//        static u16 s_unReverseCnt = 0;
//        s16 t_nSpd = 0;

//        t_nSpd = LIB_OB_MOTOR_SPD;

//        if (ABS(t_nSpd) < tS_M->mS_Para.unDetReverseSpdTH)
//        {

//            //org version, reverse --> brake
//            if (s_unReverseCnt++ >= 10)
//            {
//                s_unReverseCnt = 0;
//                tS_M->eFSM = E_FSM_SYS_BRAKE;
//            }
//        }
//#else
//        //reverse ramp mode
//        ReverseRampInitLIB(tS_M);
//#endif
//    }

//    tS_M->mS_Ctr.unThetaCmd = LIB_OB_MOTOR_THETA;
//    FOC_CurrLoop_Output(tS_M);
//    SVPWM_2R(tS_M, &gS_SVM);
//    REG_PWM_Duty_Ctr(&gS_SVM);


//}




//void FOC_Main_Loop(void)
//{
//    //foc loop
//    static STR_TrigComponents   sS_TrigSinCos;
//    sS_TrigSinCos = gS_TrigFunctions(gS_Motor.mS_Ctr.unThetaCmd);

//    FOC_GetPhaseCurrent(&gS_Motor);//rshunt = 0.1ohm, gain = 5. or rshunt = 0.05ohm, gain = 10.
//    FOC_Coordinate_ABCtoDQ(&gS_Motor, &sS_TrigSinCos);

//    if (gS_Motor.mS_Ctr.ubStateDiv == 0)
//    {
//        gS_Motor.mS_Ctr.ubStateDiv = 1;
//    }
//    else if (gS_Motor.mS_Ctr.ubStateDiv == 1)
//    {
//        gS_Motor.mS_Ctr.ubStateDiv = 0;
//    }

//    if ((gS_Motor.eFSM != E_FSM_SYS_INIT) && (gS_Motor.eFSM != E_FSM_SYS_STANDBY) && (gS_Motor.eFSM != E_FSM_SYS_STOP))
//    {
//        /*LIB_THETA_EST();*/
//    }

//#if 1
//    switch (gS_Motor.eFSM)
//    {
//    case E_FSM_SYS_INIT:

//        REG_PWM_Out_Disable();
//        ParameterInit();

//        break;

//    case E_FSM_SYS_STANDBY:

//        break;

//    case E_FSM_SYS_STOP:

//        REG_PWM_Out_Disable();
//        gS_Motor.eFSM = E_FSM_SYS_INIT;

//        break;

//    case E_FSM_SYS_SOFTSTOP:

//        MotorSoftstop(&gS_Motor);

//        break;

//    case E_FSM_SYS_PRECHARGE:

//        MotorPreCharge();

//        break;

//    case E_FSM_SYS_ALIGN:

//        MotorAlign(&gS_Motor);
//        REG_PWM_Out_Enable();

//        break;

//    case E_FSM_SYS_RAMP:

//        MotorRamp(&gS_Motor);
//        /*ALM_LostPhase(&gS_Motor);*/

//        break;

//    case E_FSM_SYS_ADAPTIVERAMP:

//        MotorAdaptiveRamp(&gS_Motor);
//        /*ALM_LostPhase(&gS_Motor);*/

//        break;


//    case E_FSM_SYS_RUN_TRANS:

//        MotorRunTrans(&gS_Motor);

//        break;

//    case E_FSM_SYS_RUN:

//        MotorRun(&gS_Motor);
//        CLEAR_RETRY_CNT();//retry clear
//        gS_Motor.mS_Ctr.ubLostPhaseCntTarget = gS_Motor.mS_Para.ubLostPhaseCntTimes;
//        /*ALM_LostPhase(&gS_Motor);*/

//        break;

//    case E_FSM_SYS_DET:

//        ADCBiasCheckRun(&gS_Motor);

//        if (gS_Motor.mS_Ctr.ubADCBiasState == ADC_BIASCHECK_DONE) //bias check done
//        {
//            LIB_DIR_DET();
//        }

//        break;

//    case E_FSM_SYS_BRAKE:

//        MotorBrake(&gS_Motor);

//        break;

////    case E_FSM_SYS_IPD:

////        MotorIPD(&gS_Motor);

////        break;
////
//    case E_FSM_SYS_REVERSE:

//        MotorReverse(&gS_Motor);

//        break;
////


//    case E_FSM_SYS_REVERSERAMP:

//        MotorReverseRamp(&gS_Motor);

//        break;

//    case E_FSM_SYS_FAULT:



//        break;


//    default:

//        break;

//    }
//#endif
//}
